package com.kexun.servlet.teacher;

import com.kexun.pojo.ScoreStu;
import com.kexun.service.TeaService;
import com.kexun.service.impl.TeaServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet("/ServletaddScore")
public class ServletaddScore extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        Map<String, String[]> map = request.getParameterMap();
        ScoreStu scoreStu = new ScoreStu();

        try {
            BeanUtils.populate(scoreStu,map);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        TeaService ts = new TeaServiceImpl();
        int i = ts.addScore(scoreStu);
        if(i>0){
           /* findScoreAll fsall = new findScoreAll();
            fsall.doPost(request,response);*/
           response.getWriter().print("恭喜你，添加成功！");
           response.setHeader("refresh","1;url=teacher/addScore.jsp");
 //           response.sendRedirect("teacher/addScore.jsp");//也可以，但是点击添加后界面闪一下后数据全清空，速度很快

        }




    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
